Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Refactor printing in CLI #931

Merged
merged 3 commits into from
Jul 24, 2017
Merged

Conversation

rasmuserik
Copy link
Contributor

This changes the CLI to use a logger instead of console.out, as discussed in #495

There is a design decision about how we instantiate the logger: originally there was a logger instantiated in command/init, but I think that instantiating it in every command, will add too much boilerplate. Instead I just took the simplest approach, i.e. to instantiate an instance in the utils module, - and have a print function exported there.

If we want to have a quiet option, it could then be parsed once in bin.js, and then the logger might be instantiated from there. Also if we intend always only have a single logger instance(?), we could remove createLogger , and just have the print function, plus the ability to configure whether to silence it or not.

License: MIT
Signed-off-by: Rasmus Erik Voel Jensen <[email protected]>
Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for PR'ing this @rasmuserik ! 🙌🏽

will add too much boilerplate. Instead I just took the simplest approach, i.e. to instantiate an instance in the utils module, - and have a print function exported there.

Yes, makes sense.

If we want to have a quiet option, it could then be parsed once in bin.js, and then the logger might be instantiated from there.

I like that, could you move forward with it?

@@ -24,7 +26,7 @@ module.exports = {
throw err
}

list.Peers.forEach((l) => console.log(l))
list.Peers.forEach(peer => print(peer))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nitpick. Change to (peer) => print(peer). Lint should have caught that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in latest version of the pull request :)

src/cli/utils.js Outdated
@@ -83,3 +83,4 @@ exports.createLogger = (visible) => {
}
}
}
exports.print = exports.createLogger(true) // TODO refactor/remove createLogger?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, go for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

License: MIT
Signed-off-by: Rasmus Erik Voel Jensen <[email protected]>
@rasmuserik
Copy link
Contributor Author

I like that, could you move forward with it?

Yep, I will do that :)

@rasmuserik
Copy link
Contributor Author

The quiet flag is now implemented :)

It is implemented as a verbosity level,
which was almost the same code, but more general,
and I added a verbose flag at the same time,
as it might also be useful(?) - otherwise I'll just remove it.

@daviddias
Copy link
Member

Mind adding tests for the new modes @rasmuserik ?

We just need:

  • q
  • regular
  • verbose

No need for multiple levels of 'verbosity'

@rasmuserik
Copy link
Contributor Author

I'll add a test for the quiet flag,
‐ and remove the verbose part.
The test of the regular mode,
should be covered by existing tests :)

License: MIT
Signed-off-by: Rasmus Erik Voel Jensen <[email protected]>
@rasmuserik
Copy link
Contributor Author

done :)

@daviddias daviddias merged commit a5e75e0 into ipfs:master Jul 24, 2017
@daviddias
Copy link
Member

Thank you @rasmuserik !! :D

dryajov pushed a commit that referenced this pull request Sep 1, 2017
* refactor: CLI should use print instead of console.log #495

License: MIT
Signed-off-by: Rasmus Erik Voel Jensen <[email protected]>

* feat: add quiet/verbose CLI flag, - related to #931

License: MIT
Signed-off-by: Rasmus Erik Voel Jensen <[email protected]>

* add test, and remove verbosity levels

License: MIT
Signed-off-by: Rasmus Erik Voel Jensen <[email protected]>
MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this pull request May 22, 2020
Excluding `ipfs-http-client` in the `browser` field of package.json was causing Meteor to not include the bundle in it's browser build.

fixes #10411

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants